#include <algorithm>
#include "InsertionSort.h"
void BubbleSort(std::vector<TYPE> &nums,bool miniToMax)
{
    for(int i=1;i<nums.size();i++){
        TYPE key = nums[i];
        int j = i-1;
        if(miniToMax){
            while((j >= 0) && (key < nums[j])){
                std::swap(nums[j+1], nums[j]);
                j--;
            }
        }else {
            while((j >= 0) && (key > nums[j])){
                std::swap(nums[j+1], nums[j]);
                j--;
            }
        }

        nums[j+1]=key;
    }
//    for (int i = 1; i < nums.size(); ++i) {
//        int key = nums[i];
//        for (int j = i-1; j >= 0; --j) {
//            if(nums[j] < key){
//                std::swap(nums[j], nums[j+1]);
//            }
//        }
//    }
}
void show(std::vector<TYPE> &nums){
    std::cout<<"nums:";
    for (int i = 0; i < nums.size(); ++i) {
        std::cout<<nums[i]<<",";
    }std::cout<<std::endl;
}

int main(){
    std::vector<int> nums = {1,3,5,7,2,6,4,8,9,2,8,7,6,0,3,5,9,4,1,0};
    show(nums);
    BubbleSort(nums,true);
    show(nums);
//    std::vector<int> nums1 = {1,3,5,7,2,6,4,8,9,2,8,7,6,0,3,5,9,4,1,0};
//    show(nums1);
//    BubbleSort(nums1, false);
//    show(nums1);
    return 0;
}